home *** CD-ROM | disk | FTP | other *** search
- /*
- A very simple echo tcp client.
- Show how to make a basic connection to a tcp service.
- To test it on localhost, be sure echo/tcp is enabeld
- in the services and inetd database, then write
- rx echotcp localhost.
- */
-
- if ~show("L","rexxsupport.library") then
- if ~addlib("rexxsupport.library",0,-30) then do
- say "no rexxsupport.library"
- exit
- end
- if ~show("L","rxsocket.library") then
- if ~addlib("rxsocket.library",0,-30) then do
- say "no rxsocket.library"
- exit
- end
- if ~show("L","rmh.library") then
- if ~addlib("rmh.library",0,-30) then do
- say "no rmh.library"
- exit
- end
-
- prg = ProgramName("NOEXT")
-
- if ~RMH_ReadArgs("HOST/A") then do
- call PrintFault(IoErr(),prg)
- exit
- end
-
- addr = resolve(parm.0.value)
- if addr=="-1" then call err "no host <"parm.0.value">"
-
- if ~getservbyname("SE","echo","tcp") then
- call err "echo tcp service not found"
-
- sin.ADDRFAMILY = "INET"
- sin.ADDRADDR = addr
- sin.ADDRPORT = SE.SERVPORT
-
- sock = socket("INET","STREAM","IP")
- if sock<0 then call err "no socket ("errno()")"
-
- if connect(sock,"SIN")<0 then call err "connect error ("errno()")"
-
- REQUEST = "echo service test"
- res = send(sock,REQUEST)
- if res~=length(REQUEST) then call err "send error ("errno()")"
-
- len = recv(sock,"BUF",256)
- if len<0 then call err "recv error ("errno()")"
-
- say buf
- call CloseSocket(sock)
- exit
-
- err: procedure expose prg
- parse arg msg
- say prg":" msg
- exit
-